
from sqlalchemy import Column, Integer, String, Numeric,Float,DateTime,DECIMAL
from db_setting.base import Base
import uuid
from datetime import datetime

class CostSubjectSummary(Base):
    __tablename__ = "cost_subject_summary"

    id = Column(String(36), primary_key=True, comment="主键ID")
    flag = Column(String(20), default="", comment="标记")
    subject_code = Column(String(50), default="", comment="科目代码")
    subject_name = Column(String(200), default="", comment="成本科目名称")

    cost_total_tax = Column(Numeric(18, 12), default=0.0, comment="含税总成本（销售+持有）（万元）")
    cost_total_no_tax = Column(Numeric(18, 12),default=0.0, comment="不含税总成本（销售+持有）（万元）")
    tax_total = Column(Numeric(18, 12), default=0.0, comment="总进税（销售+持有）（万元）")
    unit_cost_building = Column(Numeric(18, 12), default=0.0, comment="含税建面单方（元/m2）")
    unit_cost_saleable = Column(Numeric(18, 12), default=0.0, comment="含税可售单方（元/m2）")
    cost_ratio = Column(Numeric(18, 12), default=0.0, comment="占总成本比例")

    level = Column(Integer, nullable=True, comment="层级")
    full_path = Column(String(1000), nullable=True, comment="完整路径（层级名称拼接）")

    level_1 = Column(String(200), default="", comment="一级科目")
    level_2 = Column(String(200), default="", comment="二级科目")
    level_3 = Column(String(200), default="", comment="三级科目")

    created_at = Column(DateTime, default=datetime.now, comment="创建时间")


class DynamicCostSummary(Base):
    __tablename__ = "dynamic_cost_summary"

    id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))

    subject_name = Column(String(200), default="", comment="科目名称")
    category = Column(String(100), default="", comment="类别")
    contract_status = Column(String(50), default="", comment="合同状态")

    target_adjusted_cost = Column(Numeric(18, 2), default=0.0, comment="本次目标+调整成本")
    contract_signed_current = Column(Numeric(18, 2), default=0.0, comment="合同有效签约金额")
    signed_last = Column(Numeric(18, 2), default=0.0, comment="上次签约金额")
    signed_current = Column(Numeric(18, 2), default=0.0, comment="本次签约金额")
    change_last = Column(Numeric(18, 2), default=0.0, comment="上次变更金额")
    change_current = Column(Numeric(18, 2), default=0.0, comment="本次变更金额")
    pipeline_cost_last = Column(Numeric(18, 2), default=0.0, comment="上次在途成本")
    pipeline_cost_current = Column(Numeric(18, 2), default=0.0, comment="本次在途成本")
    contract_change_last = Column(Numeric(18, 2), default=0.0, comment="上次合同+变更(不含在途)")
    contract_change_current = Column(Numeric(18, 2), default=0.0, comment="本次合同+变更(不含在途)")
    estimate_change_last = Column(Numeric(18, 2), default=0.0, comment="上次预估变更")
    estimate_change_current = Column(Numeric(18, 2), default=0.0, comment="本次预估变更")
    pending_plan_last = Column(Numeric(18, 2), default=0.0, comment="上次待发生合约规划")
    pending_plan_current = Column(Numeric(18, 2), default=0.0, comment="本次待发生合约规划")
    dynamic_cost_last = Column(Numeric(18, 2), default=0.0, comment="上次动态成本")
    dynamic_cost_current = Column(Numeric(18, 2), default=0.0, comment="本次动态成本")

    code = Column(String(64), nullable=True)
    level = Column(Integer, nullable=True)
    full_path = Column(String(1000), nullable=True)
    created_at = Column(DateTime, default=datetime.now)
    level_0 = Column(String(200), default="", comment="项目成本")
    level_1 = Column(String(200), default="", comment="一级科目")
    level_2 = Column(String(200), default="", comment="二级科目")
    level_3 = Column(String(200), default="", comment="三级科目")

    